//
//  FanDianDetailViewController.m
//  FactorySale
//
//  Created by 李 on 2020/1/13.
//  Copyright © 2020 主事丫环. All rights reserved.
//

#import "FanDianDetailViewController.h"
#import "FanDianDetailTopCell.h"
#import "FanDianDetailListCell.h"

#import "FanDainDetailListModel.h"

@interface FanDianDetailViewController ()<UITableViewDelegate,UITableViewDataSource>
//列表
@property (nonatomic,strong) UITableView *listTableView;
@property (nonatomic,strong) NSMutableArray *listArray;

@end

static NSString *const FanDianListTopCellID = @"FanDianDetailTopCell";
static NSString *const XiaoShouEFanDianListCellID = @"FanDianDetailListCell";

@implementation FanDianDetailViewController
- (void)viewWillAppear:(BOOL)animated {

    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];

}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"返点详情";
    [self.leftbutton setImage:imgname(@"left_icon") forState:(UIControlStateNormal)];
       self.view.backgroundColor = Main_BackGroundColor;
    [self addBackTableView];
    [self requestSalesVolume];

}
-(void)requestSalesVolume
{
  
    NSDictionary *param = @{
        @"time":NOTNIL(self.time)
       };
    [NetWorkTool POST:salesReturnInfo param:param success:^(id dic) {
        
        self.listArray = [FanDainDetailListModel mj_objectArrayWithKeyValuesArray:dic[@"data"]];
        [self.listTableView reloadData];



    } other:^(id dic) {
         ShowToastWithText(dic[@"msg"]);

    } fail:^(NSError *error) {

    } needUser:NO];
}
-(void)addBackTableView
{
     
     [self.listTableView registerClass:[FanDianDetailTopCell class] forCellReuseIdentifier:FanDianListTopCellID];
     [self.listTableView registerClass:[FanDianDetailListCell class] forCellReuseIdentifier:XiaoShouEFanDianListCellID];
    [self.view addSubview:self.listTableView];
     
}
- (UITableView *)listTableView
{
    if (!_listTableView) {
        _listTableView = [[UITableView alloc] initWithFrame:CGRectMake(0,kNaviHeight, SCREEN_WIDTH, SCREEN_HEIGHT-kNaviHeight-TabbarSafeBottomMargin) style:UITableViewStylePlain];
        _listTableView.delegate = self;
        _listTableView.dataSource = self;
        _listTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
        _listTableView.estimatedSectionHeaderHeight = 0;
        _listTableView.estimatedSectionFooterHeight = 0;
        _listTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _listTableView.backgroundColor =  Main_BackGroundColor;
    }
    return _listTableView;
}
#pragma mark UITableView
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{

    return 10;

}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{

    return 0.01;

}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    UIView *headerView = [[UIView alloc] init];
    headerView.backgroundColor = Main_BackGroundColor;
    headerView.frame = CGRectMake(0, 0, KWIDTH, 10);
    return headerView;
    
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
       return nil;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (self.listArray.count>0) {
        return self.listArray.count+1;
    }
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row ==0) {
        return 45.5;
    }
    else {
        return 40.5;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==0) {
        FanDianDetailTopCell *cell = [tableView dequeueReusableCellWithIdentifier:FanDianListTopCellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    if (indexPath.row>0) {
      
        FanDainDetailListModel *model = [self.listArray safeObjectAtIndex:indexPath.row-1];
        
        FanDianDetailListCell *cell = [tableView dequeueReusableCellWithIdentifier:XiaoShouEFanDianListCellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.model = model;
        
        return cell;
    }
     NSString *cellIdentifier = @"iden3";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
                   cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
               }

    return cell;

}

@end
